<?php
class database{
	protected $conn = "";
	protected $result = "";
	public function __construct(){
		$this->conn = mysql_connect(config::HOST,config::USER,config::PASS) or die("Can't connect database");
		mysql_select_db(config::DBNAME,$this->conn);
		mysql_query("SET NAMES utf8");
		
	}
	public function query($sql){
		$this->result = mysql_query($sql);
	}
	public function num_rows(){
		if($this->result){
			$rows = mysql_num_rows($this->result);
		}else{
			$rows = 0;
		}
		return $rows;
	}
	public function fetch(){
		if($this->result){
			$data = mysql_fetch_assoc($this->result);
		}else{
			$data = array();
		}
		return $data;
	}
	public function debug($val){
		echo "<pre>";
		print_r($val);
		echo "</pre>";
	}
	public function fetchAll(){
		if($this->result){
			while($db = mysql_fetch_assoc($this->result)){
				$data[] = $db;
			}
		}else{
			$data = array();
		}
		return $data;
	}
}